package com.xwdeshj.controller;

import com.alibaba.fastjson.JSONObject;
import com.xwdeshj.service.XwCityinfoService;
import com.xwdeshj.utils.IMoocExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * Created by BKWJA on 2018/12/19.
 * 城市管理控制层
 */
@Slf4j
@CrossOrigin(allowCredentials = "true")
@RequestMapping("city")
@Controller
public class XwCityinfoController extends IMoocExceptionHandler {

    @Autowired
    private XwCityinfoService xwCityinfoService;

    /**
     * 城市列表查询
     * @param pageindex 当前页码
     * @param pagesize 每页显示多少
     * @param starttime 开始时间
     * @param endtime 结束时间
     * @param searchval 搜索内容
     * @param searchkey 搜索字段
     * @param sortfild 排序字段
     * @param sortway 排序方式
     * @return
     */
    @RequestMapping("/getCityinfolist")
    @ResponseBody
    public JSONObject getCityinfolist(@RequestParam(value = "pageindex",defaultValue = "1")Integer pageindex,
                                      @RequestParam(value = "pagesize",defaultValue = "10") Integer pagesize,
                                      @RequestParam(value = "starttime",defaultValue = "") String starttime,
                                      @RequestParam(value = "endtime",defaultValue = "") String endtime,
                                      @RequestParam(value = "searchval",defaultValue = "") String searchval,
                                      @RequestParam(value = "searchkey",defaultValue = "") String searchkey,
                                      @RequestParam(value = "sortfild",defaultValue = "city_updatetime") String sortfild,
                                      @RequestParam(value = "sortway",defaultValue = "desc")String sortway){
        searchval.trim();
        return xwCityinfoService.getCityinfolist(pageindex,pagesize,starttime,endtime,searchval,searchkey,sortfild,sortway);
    }

    /**
     * 修改，新增城市信息
     * @param city_encryptId 城市加密id
     * @param city_name 城市名称
     * @param city_district_name 区县名称
     * @return
     */
    @RequestMapping("/updatecityinfo")
    @ResponseBody
    public JSONObject updatecityinfo(String city_encryptId,String city_name,String city_district_name){
        return xwCityinfoService.updatecityinfo(city_encryptId,city_name,city_district_name);
    }

    /**
     * 删除
     * @param city_encryptId
     * @return
     */
    @RequestMapping("/delcityinfo")
    @ResponseBody
    public JSONObject delcityinfo(String city_encryptId){
        return xwCityinfoService.delcityinfo(city_encryptId);
    }




}
